<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>Hello</title>
		<script src="js/jquery.min.js"></script>
		<style></style>
	</head>
	<body>
		<img src=""/>
		<button onclick="a()">按钮a</button>
		<button onclick="b()">按钮b</button>
	</body>

	<script>
		var imgSrc = "image/box.png";
		function getBase64Image(img, width, height) {
		      var canvas = document.createElement("canvas");
		      canvas.width = width ? width : img.width;
		      canvas.height = height ? height : img.height;
		      var ctx = canvas.getContext("2d");
		      ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
		      var dataURL = canvas.toDataURL();
		      return dataURL;
		    }
		
		    function getCanvasBase64(img) {
		      var image = new Image();
		      //至关重要
		      image.crossOrigin = '';
		      image.src = img;
		      //至关重要
		      var deferred = jQuery.Deferred();
		      if (img) {
		        image.onload = function () {
		          deferred.resolve(getBase64Image(image));//将base64传给done上传处理
		          // document.getElementById("container2").appendChild(image);
		        }
		        return deferred.promise();//问题要让onload完成后再return sessionStorage['imgTest']
		      }
		    }
		    getCanvasBase64(imgSrc).then(function (base64) {
		        console.log("方式二》》》》》》》》》",base64);
		      }, function (err) {
		        console.log(err);
		      });
		
		
		
		function a(){
			mui.ajax({
				type:"post",
				url: 'http://127.0.0.1:8080/myPro2_war_exploded/login_Servlet',
				async:false,
				data: {
					name:"username",
					password:"123456"
				},
				dataType: "json",
				contentType: "application/x-www-form-urlencoded; charset=utf-8",
				jsonp: "jsoncallback",
				success: function(data){
					console.log("success");
				},
				error: function(){
					console.log("error");
				}
			});
		}
		
		function b(){
			mui.openWindow('test.html?a=123');
		}
		
	</script>
</html>
